package com.doubleview.demo


/**
 * @author huchengchao <huchengchao@kuaishou.com>
 * Created on 2021-11-20
 */

// 全包含的range
def range = 5..8
assert range.size() == 4
assert range.get(2) == 7
assert range[2] == 7
assert range instanceof java.util.List
assert range.contains(5)
assert range.contains(8)

// 半开的range
range = 5..<8
assert range.size() == 3
assert range.get(2) == 7
assert range[2] == 7
assert range instanceof java.util.List
assert range.contains(5)
assert !range.contains(8)

//获取range的端点而不使用索引
range = 1..10
assert range.from == 1
assert range.to == 10

// 全包括range
range = 'a'..'d'
assert range.size() == 4
assert range.get(2) == 'c'
assert range[2] == 'c'
assert range instanceof java.util.List
assert range.contains('a')
assert range.contains('d')
assert !range.contains('e')

// 使用each方法迭代Range
(1..10).each { i ->
    println "Hello ${i}"
}

"aa".eachLine {
    println(it)
}
